package leets.leet2266;

public class Solution {
    public int countTexts(String pressedKeys) {
        long[] res=new long[pressedKeys.length()];
        res[0]=1;
        for (int i = 1; i < pressedKeys.length(); i++) {
            res[i]=(res[i-1]%(1000000000+7));
            char c=pressedKeys.charAt(i);
           int bound=(c=='7'||c=='9')?4:3;
            for (int j=i-1;j>=Math.max(0,i-bound+1);j--){
                if(c==pressedKeys.charAt(j)){

                    if(j>0){
                        res[i]+=res[j-1];
                    }else {
                        res[i]++;
                    }
                }else {
                    break;
                }
            }
        }
        return (int) ((res[res.length-1])%(1000000000+7));
    }
}
